<?php

if(isset($_POST['val']))
{
$val1 = $_POST['val'];
$type2 = $_POST['type'];
$typeb = $_POST['typeb'];
$output = "";
}

if($type2 == "img")
{
	$output=$output.'<table><tr><td>
	<div style="max-height:200px; overflow:auto;padding:5px;">
	<a href="'.$val1.'" target="_blank"><img src="'.$val1.'" style="width:150px;" class="img" /></a>
	</div>
	</td><td valign="top"><!--<span style="color:#888;font-size:8pt">image</span><br>-->';
	
	if(isset($_POST['val']))
	$output=$output.'<span class="a" onclick=\'post_insert_media(this, "remove", "'.$typeb.'")\'>remove image</span>';
	
	$output=$output.'</td></tr></table>';
}
else if($type2 == "vid")
{
    $url = "http://gdata.youtube.com/feeds/api/videos/". $val1;
    $doc = new DOMDocument;
    $doc->load($url);

		
	$output=$output.'<table><tr><td >
	<div style="max-height:200px; overflow:auto;padding:5px;">
	<a href="http://www.youtube.com/watch?v='.$val1.'" target="_blank"><div style="width:150px;position:relative">';
	//if(isset($_POST['val']))
	$output=$output.'<img src="'.$site_url.'images/play.png" style="position:absolute;left:50%;top:50%;width:40px;margin-left:-20px;margin-top:-20px;opacity:0.9;z-index:10">';
	$output=$output.'<img src="http://img.youtube.com/vi/'.$val1.'/default.jpg" style="width:150px" /></div></a>';
	$output=$output.'</div>	
	</td><td valign="top"><!--<span style="color:#888;font-size:8pt">youtube video</span>-->
	<br><strong><a href="http://www.youtube.com/watch?v='.$val1.'" target="_blank">'.$title.'</a></strong><br>';
	
	if(isset($_POST['val']))
	$output=$output.'<span class="a" onclick=\'post_insert_media(this, "remove","'.$typeb.'")\'>remove video</span>';
	
	$output=$output."</td></tr></table>";
}
else
{
	$output=$output."Invalid media type!<br>";
}

if(isset($_POST['val']))
 	echo $output;




?>